package cn.tk.model.entity.mr;

import cn.tk.model.entity.AbstractEntity;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Objects;

/**
 * Created by denglw on 2021/7/16.<br/>
 * Desc: 流程节点
 */
@Data @NoArgsConstructor
@Entity(name = "mrFlowNode")
@Table(name = "mr_bot_flow_node")
public class FlowNode extends AbstractEntity {

    /**
     * botid
     */
    private Long botId;

    /**
     * 流程id
     */
    private Long flowId;

    /**
     * 节点名称
     */
    private String name;

    /**
     * 节点类型：1话术节点，2条件节点，3函数节点，4实体节点
     */
    private Integer type;

    /**
     * 是否开始节点：0否 1是
     */
    private Boolean ifStart;

    public boolean isReplyNode() {
        return Objects.equals(type, 1);
    }

    public boolean isConditionNode() {
        return Objects.equals(type, 2);
    }

    public boolean isFuncNode() {
        return Objects.equals(type, 3);
    }

    public boolean isEntityNode() {
        return Objects.equals(type, 4);
    }

    public boolean isReplyNode(int type) {
        return Objects.equals(type, 1);
    }

    public boolean isConditionNode(int type) {
        return Objects.equals(type, 2);
    }

    public boolean isFuncNode(int type) {
        return Objects.equals(type, 3);
    }

    public boolean isEntityNode(int type) {
        return Objects.equals(type, 4);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof FlowNode)) {
            return false;
        }
        FlowNode flowNode = (FlowNode) o;
        return Objects.equals(flowNode.getId(), getId())
                && Objects.equals(botId, flowNode.botId)
                && Objects.equals(flowId, flowNode.flowId)
                && Objects.equals(name, flowNode.name)
                && Objects.equals(type, flowNode.type)
                && Objects.equals(ifStart, flowNode.ifStart);
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId(), botId, flowId, name, type, ifStart);
    }
}
